using System.Collections;
using UnityEngine;

public class QualityLabel : MonoBehaviour
{
	public UILabel label;

	public float duration = 1f;

	public float fadeInOut = 0.1f;

	public FloatRange alphaRange = default(FloatRange);

	private Vector3 worldPosition;

	private bool initialized;

	private void Awake()
	{
		Init();
	}

	private void Init()
	{
		if (!initialized)
		{
			initialized = true;
			base.gameObject.SetActive(false);
		}
	}

	public void SetQuality(string quality, Color color, Vector3 worldPosition)
	{
		Init();
		label.color = color;
		label.text = quality.ToUpper();
		label.cachedGameObject.SetActive(true);
		this.worldPosition = worldPosition;
		SetWorldPosition(worldPosition);
		StopAllCoroutines();
		if (base.gameObject.activeInHierarchy)
		{
			StartCoroutine(DoShowQuality());
		}
	}

	public void SetWorldPosition(Vector3 worldPosition)
	{
		Vector3 position = UICamera.mainCamera.ScreenToWorldPoint(Camera.main.WorldToScreenPoint(worldPosition));
		position.z = label.cachedTransform.position.z;
		label.cachedTransform.position = position;
	}

	public void Hide()
	{
		label.text = string.Empty;
		StopAllCoroutines();
		TweenAlpha.Begin(label.cachedGameObject, fadeInOut, alphaRange.min);
	}

	public IEnumerator DoShowQuality()
	{
		label.alpha = alphaRange.min;
		label.cachedTransform.localScale = new Vector3(1f, 0f, 1f);
		TweenScale.Begin(label.cachedGameObject, fadeInOut, Vector3.one);
		TweenAlpha.Begin(label.cachedGameObject, fadeInOut, alphaRange.max);
		yield return new WaitForSeconds(duration + fadeInOut);
		TweenAlpha.Begin(label.cachedGameObject, fadeInOut, alphaRange.min);
		yield return new WaitForSeconds(fadeInOut);
		label.cachedGameObject.SetActive(false);
	}

	private void Update()
	{
		SetWorldPosition(worldPosition);
	}
}
